wait_timeout = "10"
send_loop_times = 10

QC_socket_cmd = [
    {
        "cmd": 'AT+QICLOSE=0',
        "match": 'AT\+QICLOSE=0\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QIDEACT=1',
        "match": 'AT\+QIDEACT=1\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QICFG="recvind",1',
        "match": 'AT\+QICFG="recvind",1\s{3}OK\s{2}',
    },
    # 基本命令
    {
        "cmd": 'AT+QICSGP=?',
        "match": 'AT\+QICSGP=\?\s{3}\+QICSGP: \(1-15\),\(1-3\),<APN>,<username>,<password>,\(0-3\),\(0-1\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIACT=?',
        "match": 'AT\+QIACT=\?\s{3}\+QIACT: \(1-15\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIACT?',
        "match": 'AT\+QIACT\?\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QIOPEN=?',
        "match": 'AT\+QIOPEN=\?\s{3}\+QIOPEN: \(1-15\),\(0-11\),"TCP\/UDP\/TCP LISTENER\/UDP SERVICE","<IP_address>\/<domain_name>",<remote_port>,<local_port>,\(0-2\),<tcp_client_maxnum>\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QICLOSE=?',
        "match": 'AT\+QICLOSE=\?\s{3}\+QICLOSE: \(0-11\),\(0-65535\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISTATE?',
        "match": 'AT\+QISTATE\?\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QISTATE=?',
        "match": 'AT\+QISTATE=\?\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QISEND=?',
        "match": 'AT\+QISEND=\?\s{3}\+QISEND: \(0-11\),\(0-1460\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIRD=?',
        "match": 'AT\+QIRD=\?\s{3}\+QIRD: \(0-11\),\(0-1500\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISENDEX=?',
        "match": 'AT\+QISENDEX=\?\s{3}\+QISENDEX: \(0-11\),<hex_string>\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISWTMD=?',
        "match": 'AT\+QISWTMD=\?\s{3}\+QISWTMD: \(0-11\),\(0-2\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QPING=?',
        "match": 'AT\+QPING=\?\s{3}\+QPING: \(1-15\),<host>,\(1-255\),\(1-10\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QNTP?',
        "match": 'AT\+QNTP\?\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QNTP=?',
        "match": 'AT\+QNTP=\?\s{3}\+QNTP: \(1-15\),<server>,\(1-65535\),\(0,1\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIDNSCFG=?',
        "match": 'AT\+QIDNSCFG=\?\s{3}\+QIDNSCFG: \(1-15\),<pridnsaddr>,<secdnsaddr>\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIDNSGIP=?',
        "match": 'AT\+QIDNSGIP=\?\s{3}\+QIDNSGIP: \(1-15\),<hostname>\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISDE=?',
        "match": 'AT\+QISDE=\?\s{3}\+QISDE: \(0,1\)\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISDE?',
        "match": 'AT\+QISDE\?\s{3}\+QISDE: \d\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIGETERROR=?',
        "match": 'AT\+QIGETERROR=\?\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QICFG=?',
        "match": '\s{2}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    # TCP
    {
        "cmd": 'AT+QICSGP=1,1,"UNINET","","" ,1',
        "match": 'AT\+QICSGP=1,1,"UNINET","","" ,1\s{3}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIACT=1',
        "match": 'AT\+QIACT=1\s{3}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIACT?',
        "match": 'AT\+QIACT\?\s{3}\+QIACT: 1,1,1,"[\.\d]+"\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIOPEN=1,0,"TCP","airtest.openluat.com",2901,0,0',
        "match": 'AT\+QIOPEN=1,0,"TCP","airtest.openluat.com",2901,0,0\s{3}OK\s{4}\+QIOPEN: 0,0\s{2}',
        "wait": b'+QIOPEN: 0,0',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISTATE=1,0',
        "match": 'AT\+QISTATE=1,0\s{3}\+QISTATE: 0,"TCP","114.55.242.59",2901,0,2,1,0,0,"usbat"\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISEND=0,1360',
        "match": 'AT\+QISEND=0,1360\s{3}> ',
    },
    {
        "cmd": '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',
        "match": '\d{1360}\s{2}SEND OK\s{4}\+QIURC: "recv",0,1360\s{2}',
        "enter": False,
        "wait": b'+QIURC: "recv",0',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIRD=0,1500',
        "match": 'AT\+QIRD=0,1500\s{3}\+QIRD: 1360\s{2}\d{1360}\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISEND=0,0',
        "match": 'AT\+QISEND=0,0\s{3}\+QISEND: 1360,1360,0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISENDEX=0,"3031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343530313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435"',
        "match": 'AT\+QISENDEX=0,"3031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343530313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435"\s{3}SEND OK\s{4}\+QIURC: "recv",0,512\s{2}',
        "wait": b'+QIURC: "recv",0,512',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIRD=0,1500',
        "match": 'AT\+QIRD=0,1500\s{3}\+QIRD: 512\s{2}\d{512}\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIRD=0,1500',
        "match": 'AT\+QIRD=0,1500\s{3}\+QIRD: 0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISEND=0,0',
        "match": 'AT\+QISEND=0,0\s{3}\+QISEND: 1872,1872,0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIRD=0,0',
        "match": 'AT\+QIRD=0,0\s{3}\+QIRD: 1872,1872,0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QICLOSE=0',
        "match": 'AT\+QICLOSE=0\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QIOPEN=1,0,"TCP","airtest.openluat.com",2901,0,2',
        "match": 'AT\+QIOPEN=1,0,"TCP","airtest.openluat.com",2901,0,2\s{3}CONNECT\s{2}',
        "wait": b'CONNECT',
        "timeout": wait_timeout
    },
    {
        "cmd": '1234567890',
        "match": '1234567890\s{2}',
        "loop": send_loop_times,
        "wait": b'1234567890',
        "timeout": wait_timeout
    },
    {
        "cmd": '+++',
        "match": '\s{2}OK\s{2}',
        "enter": False,
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QICLOSE=0',
        "match": 'AT\+QICLOSE=0\s{3}OK\s{2}',
    },
    {
        "cmd": 'AT+QIOPEN=1,0,"TCP","airtest.openluat.com",2901,0,1',
        "match": 'AT\+QIOPEN=1,0,"TCP","airtest.openluat.com",2901,0,1\s{3}OK\s{4}\+QIOPEN: 0,0\s{2}',
        "wait": b'+QIOPEN: 0,0',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISTATE=1,0',
        "match": 'AT\+QISTATE=1,0\s{3}\+QISTATE: 0,"TCP","114.55.242.59",2901,0,2,1,0,1,"usbat"\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISEND=0,1360',
        "match": 'AT\+QISEND=0,1360\s{3}> ',
    },
    {
        "cmd": '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',
        "match": '\d{1360}\s{2}SEND OK\s{4}\+QIURC: "recv",0,1360\s{2}\d{1360}\s{2}',
        "enter": False,
        "wait": b'+QIURC: "recv",0,',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISEND=0,0',
        "match": 'AT\+QISEND=0,0\s{3}\+QISEND: 1360,1360,0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISENDEX=0,"3031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343530313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435"',
        "match": 'AT\+QISENDEX=0,"3031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343530313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435"\s{3}SEND OK\s{4}\+QIURC: "recv",0,512\s{2}\d{512}\s{2}',
        "wait": b'+QIURC: "recv",0,512',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISEND=0,0',
        "match": 'AT\+QISEND=0,0\s{3}\+QISEND: 1872,1872,0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIRD=0,0',
        "match": 'AT\+QIRD=0,0\s{3}\+QIRD: 1872,1872,0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QICLOSE=0',
        "match": 'AT\+QICLOSE=0\s{3}OK\s{2}',
    },
    # UDP
    {
        "cmd": 'AT+QIOPEN=1,2,"UDP SERVICE","127.0.0.1",0,3030,0',
        "match": 'AT\+QIOPEN=1,2,"UDP SERVICE","127.0.0.1",0,3030,0\s{3}OK\s{4}\+QIOPEN: 2,0\s{2}',
        "wait": b'+QIOPEN: 2,0',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISTATE=0,1',
        "match": 'AT\+QISTATE=0,1\s{3}\+QISTATE: 2,"UDP SERVICE","[\.\d]+",0,3030,2,1,2,0,"usbat"\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QISEND=2,1024,"114.55.242.59",2902',
        "match": 'AT\+QISEND=2,1024,"114.55.242.59",2902\s{3}> ',
    },
   {
        "cmd": '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234',
        "match": '\d{1024}\s{2}SEND OK\s{4}\+QIURC: "recv",2,1024\s{2}',
        "enter": False,
        "wait": b'+QIURC: "recv",2,1024',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIRD=2',
        "match": 'AT\+QIRD=2\s{3}\+QIRD: 1024,"114.55.242.59",2902\s{2}\d{1024}\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QIRD=2',
        "match": 'AT\+QIRD=2\s{3}\+QIRD: 0\s{4}OK\s{2}',
        "wait": b'OK',
        "timeout": wait_timeout
    },
    {
        "cmd": 'AT+QICLOSE=0',
        "match": 'AT\+QICLOSE=0\s{3}OK\s{2}',
    },
]
